#!/bin/bash
# Status script for wmfs
# ~/.config/wmfs/status.sh

#
# if you want to have "conky" in your statusbar, just had this in your status.sh :
# conky | while read -r; do wmfs -s -name "$REPLY"; done
#

RED="\\#BF4D80\\"
YEL="\\#C4A1E6\\"
GRN="\\#287373\\"
CYN="\\#6096BF\\"
MAG="\\#7E62B3\\"
GRY="\\#666666\\"
WHT="\\#C0C0C0\\"
GRE="\\#A3A3A3\\"

while true;
do
    # Collect system information 
    BAT1=`acpi -V | awk '{ gsub(/,/, "");} NR==1 {print $4}'`
    BAT2=`acpi -b | grep "Battery" | awk '{print $5}' | cut -c 1-2`
    BAT3=`acpi -b | grep "Battery" | awk '{print $5}' | cut -c 4-5`
    MEM1=`free -m | awk '/buffers\/cache/{print $3}'`
    MEM2=20
    MEM=`echo "$MEM1 / $MEM2" | bc`
    CPU=`eval $(awk '/^cpu /{print "previdle=" $5 "; prevtotal=" $2+$3+$4+$5 }' /proc/stat); sleep 0.4; eval $(awk '/^cpu /{print "idle=" $5 "; total=" $2+$3+$4+$5 }' /proc/stat); intervaltotal=$((total-${prevtotal:-0})); echo "$((100*( (intervaltotal) - ($idle-${previdle:-0}) ) / (intervaltotal) ))"`
    VOL=`aumix -v q|sed "s/,.*//g" | awk '/vol/ {print $2}'`
    BRIT=`cat /sys/class/backlight/psblvds/actual_brightness`
    WIFI1=`cat /sys/class/net/wlan0/wireless/link`
    WIFI2=0.7
    WIFI=`echo "$WIFI1 / $WIFI2" | bc`
    DATE=`date "+%H:%M"`
top
    # Pipe to status bar
    wmfs -s 0 "$GRE•  $GRY[CPU $GRE$CPU%$GRY] [RAM $GRE$MEM%$GRY] [VOL $GRE$VOL%$GRY] [BRIT $GRE$BRIT%$GRY] [WIFI $GRE$WIFI%$GRY] [BAT $GRE$BAT1 $BAT2:$BAT3$GRY]$GRE  • $WHT$DATE  •"
  sleep 1
done